package com.cin.cma.common.model;

import com.cin.cma.common.enums.OpenApiErrorCode;
import com.cin.cma.common.enums.SystemErrorCode;
import com.cin.cma.common.exception.UserFriendlyException;
import lombok.Data;

import java.io.Serializable;


@Data
/**
 * 业务处理失败
 */
public class ApiErrorInfo implements Serializable {
    /**
     * 错误码
     */
    private String code;
    /**
     * 错误描述
     */
    private String message;

    public ApiErrorInfo(String code, String message) {
        this.code = code;
        this.message = message;
    }


    /**
     * 抛出未知异常，详细看描述错误
     *
     * @param message
     */
    public ApiErrorInfo(String message) {
        this.message = message;
        this.code = SystemErrorCode.SYSTEM_ERROR.getCode();
    }

    public ApiErrorInfo(SystemErrorCode errorCode, String message) {
        this.message = errorCode.getMessage() + "::" + message;
        this.code = errorCode.getCode();
    }

    public ApiErrorInfo(UserFriendlyException errorCode) {
        this.message = errorCode.getMessage();
        this.code = errorCode.getCode();
    }
    public ApiErrorInfo(OpenApiErrorCode errorCode) {
        this.message = errorCode.getMessage();
        this.code = errorCode.getCode();
    }
}
